package com.example.administrator.test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/9/2.
 */

public class CommentAdapter extends BaseAdapter {
    Context context;
    List<Comment> list;
    LayoutInflater inflater;

    public CommentAdapter(Context context,List<Comment> list){
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            view = inflater.inflate(R.layout.book_detail_comment_item,null);
            viewHolder = new ViewHolder();
            viewHolder.content = (TextView) view.findViewById(R.id.comment_content);
            viewHolder.account = (TextView)view.findViewById(R.id.comment_account);
            viewHolder.time = (TextView)view.findViewById(R.id.comment_time);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)view.getTag();
        }
        viewHolder.content.setText(list.get(i).getContent());
        viewHolder.account.setText(list.get(i).getAccount()+":");
        viewHolder.time.setText(list.get(i).getTime());
        return view;
    }

    class ViewHolder{
        TextView content;
        TextView account;
        TextView time;
    }
}
